package cate.game.client.interceptor;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.interceptor.anno.ShutUpWorldTree;
import cate.game.client.msg.MsgInput;
import cate.game.log.GameLoggerFactory;
import org.slf4j.Logger;


public class ShutupWorldTreeInterceptor extends AbstractCommandInterceptor{
    @Override
    public void execute(MsgInput msgInput, GameBody gameBody, ClientContext clientContext) {
        ShutUpWorldTree setter = msgInput.getClass().getAnnotation(ShutUpWorldTree.class);
        if(setter != null){
            if(clientContext.getRole() == null){
                Logger logger = GameLoggerFactory.getLogger(gameBody, ShutupWorldTreeInterceptor.class);
                logger.error("cc.getRole为空，msg class={}", msgInput.getClass().getName());
                return;
            }
            clientContext.getRole().getRes().worldTree.heroShare.shutup();
        }
        try {
            next.execute(msgInput, gameBody, clientContext);
        } catch (Exception e) {
            Logger logger = GameLoggerFactory.getLogger(gameBody, ShutupWorldTreeInterceptor.class);
            logger.error("Caught optimistic locking exception: ", e);
        } finally {
            if(setter != null){
                clientContext.getRole().getRes().worldTree.heroShare.openYourMouthBaby();
            }
        }
    }
}
